<?php

namespace App\Http\Controllers\API;

use App\Http\Requests\API\CreateDistributionStatisticsAPIRequest;
use App\Http\Requests\API\UpdateDistributionStatisticsAPIRequest;
use App\Models\DistributionStatistics;
use App\Repositories\DistributionStatisticsRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

/**
 * Class DistributionStatisticsController
 * @package App\Http\Controllers\API
 */

class DistributionStatisticsAPIController extends AppBaseController
{
    /** @var  DistributionStatisticsRepository */
    private $distributionStatisticsRepository;

    public function __construct(DistributionStatisticsRepository $distributionStatisticsRepo)
    {
        $this->distributionStatisticsRepository = $distributionStatisticsRepo;
    }

    /**
     * Display a listing of the DistributionStatistics.
     * GET|HEAD /distributionStatistics
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->distributionStatisticsRepository->pushCriteria(new RequestCriteria($request));
        $this->distributionStatisticsRepository->pushCriteria(new LimitOffsetCriteria($request));
        $distributionStatistics = $this->distributionStatisticsRepository->all();

        return $this->sendResponse($distributionStatistics->toArray(), 'Distribution Statistics retrieved successfully');
    }

    /**
     * Store a newly created DistributionStatistics in storage.
     * POST /distributionStatistics
     *
     * @param CreateDistributionStatisticsAPIRequest $request
     *
     * @return Response
     */
    public function store(CreateDistributionStatisticsAPIRequest $request)
    {
        $input = $request->all();

        $distributionStatistics = $this->distributionStatisticsRepository->create($input);

        return $this->sendResponse($distributionStatistics->toArray(), 'Distribution Statistics saved successfully');
    }

    /**
     * Display the specified DistributionStatistics.
     * GET|HEAD /distributionStatistics/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        /** @var DistributionStatistics $distributionStatistics */
        $distributionStatistics = $this->distributionStatisticsRepository->findWithoutFail($id);

        if (empty($distributionStatistics)) {
            return $this->sendError('Distribution Statistics not found');
        }

        return $this->sendResponse($distributionStatistics->toArray(), 'Distribution Statistics retrieved successfully');
    }

    /**
     * Update the specified DistributionStatistics in storage.
     * PUT/PATCH /distributionStatistics/{id}
     *
     * @param  int $id
     * @param UpdateDistributionStatisticsAPIRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateDistributionStatisticsAPIRequest $request)
    {
        $input = $request->all();

        /** @var DistributionStatistics $distributionStatistics */
        $distributionStatistics = $this->distributionStatisticsRepository->findWithoutFail($id);

        if (empty($distributionStatistics)) {
            return $this->sendError('Distribution Statistics not found');
        }

        $distributionStatistics = $this->distributionStatisticsRepository->update($input, $id);

        return $this->sendResponse($distributionStatistics->toArray(), 'DistributionStatistics updated successfully');
    }

    /**
     * Remove the specified DistributionStatistics from storage.
     * DELETE /distributionStatistics/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        /** @var DistributionStatistics $distributionStatistics */
        $distributionStatistics = $this->distributionStatisticsRepository->findWithoutFail($id);

        if (empty($distributionStatistics)) {
            return $this->sendError('Distribution Statistics not found');
        }

        $distributionStatistics->delete();

        return $this->sendResponse($id, 'Distribution Statistics deleted successfully');
    }
}
